package Engine.UIControl
{
	import Interface.UIControl.IButton;
	
	import Engine.UIControl.UIBase;
	
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	import library.Function.GlobalFun;
	
	public class Button extends UIBase implements IButton
	{
		private static var mouseInFilters:Array = new Array();
		
		private var _onClickParam:Object = null;
		private var _onClickFun:Function = null;
		
		private var _moveState:Boolean;    //是否存在按下 弹起
		private var _mouseInState:Boolean; //鼠标进入是否高亮
		
		private var _helpText:String = "";
		
		public function Button(p_content:Sprite)
		{
			super(p_content);
			if(mouseInFilters.length == 0)
			{
				mouseInFilters.push(GlobalFun.getEnterColorFilter());
			}
			this.initControl();
		}
		
		private function initControl():void
		{
			this._moveState = true;
			this._mouseInState = true;
			this._content.buttonMode = true;
		}
		
		override protected function onMouseClick(event:MouseEvent):void
		{
			if(this._onClickFun != null)
			{
				if(this._onClickParam != null)
					this._onClickFun(this._onClickParam);
				else
					this._onClickFun();
			}
		}
		
		override protected function onMouseDown(event:MouseEvent):void
		{
			if(this._moveState)
			{
				this.x += 1;
				this.y += 1;
			}
		}
		
		override protected function onMouseUp(event:MouseEvent):void
		{
			if(this._moveState)
			{
				this.x -= 1;
				this.y -= 1;
			}
		}
		
		override protected function onMouseIn(event:MouseEvent):void
		{
			if(this._mouseInState)
			{
				this._content.filters = mouseInFilters;
			}
		}
		
		override protected function onMouseOut(event:MouseEvent):void
		{
			this._content.filters = this._normalFilters;
		}
		
		public function setOnClickFun(fun:Function):void
		{
			this._onClickFun = fun;
		}
		
		public function setOnClickParam(param:Object):void
		{
			this._onClickParam = param;
		}
		
		public function setMoveState(state:Boolean):void
		{
			this._moveState = state;
		}
		
		public function setMouseInState(state:Boolean):void
		{
			this._mouseInState = state;
		}
		
		public function setHelpText(text:String):void
		{
			this._helpText = text;
		}
		
	}
}